package com.gecba.system.controller;

import com.gecba.system.entity.SysRole;
import com.gecba.system.service.SysRoleService;
import com.gecba.system.util.PageUtil;
import com.gecba.system.vo.PageVO;
import com.gecba.system.vo.Result;
import com.gecba.system.vo.SearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author ChenBo
 * @className SysRoleController
 * @date 2021/7/25
 */
@Api(tags = "系统角色")
@Slf4j
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService roleService;

    @ApiOperation(value = "多条件分页获取角色列表")
    @GetMapping("/pageList")
    public Result<?> pageList(SysRole sysRole, SearchVO searchVO, PageVO pageVO){

        Page<SysRole> rolePage = roleService.pageList(sysRole,searchVO, PageUtil.initPage(pageVO));
        return Result.OK(rolePage);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody SysRole role){
        SysRole sysRole = roleService.save(role);
        return Result.OK();
    }

    @PutMapping("/edit")
    public Result<?> edit(@RequestBody SysRole role){
        SysRole sysRole = roleService.saveOrUpdate(role);
        return Result.OK();
    }

    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam("id") Long id){
        roleService.delete(id);
        return Result.OK();
    }


}
